<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width,initial-scale=1.0" />
    <script src="./js/earthsdk.js"></script>
    <script src="./js/Colorpicker.js"></script>
    <!-- 自定义Css样式 -->
    <link rel="stylesheet" href="./css/example1.css" />
    <title>GeoJSON</title>
    <style>
        html,
        body,
        #app {
            width: 100%;
            height: 100%;
            margin: 0px;
            padding: 0px;
        }
    </style>
</head>

<body>
    <div id="app"></div>
    <div id="panel">
        <div class="box">
            <button onclick="flyTo()">飞行定位</button>
        </div>
    </div>
    <script>
        /** ---------------------------------地球创建------------------------------------**/
        // Vue中引入方式：import { ESObjectsManager } from 'earthsdk3';
        const { ESObjectsManager } = window['EarthSDK3']
        const { ESCesiumViewer } = window['EarthSDK3_Cesium']
        const { ESUeViewer } = window['EarthSDK3_UE']
        const objm = new ESObjectsManager(ESCesiumViewer, ESUeViewer);
        window.g_objm = objm;
        // 监听视口状态
        objm.viewerCreatedEvent.don((viewer) => {
            viewer.flyIn(
                [
                    112.45780919788025,
                    18.19693250176904,
                    2144551.2822136437
                ],
                [
                    0.06449822108129306,
                    -60.018767852031814,
                    359.99975834694095
                ],
                3
            )
            // 监听clickEvent鼠标事件
            viewer.clickEvent.don((e) => {
                // pick拾取
                viewer.pick(e.screenPosition, "customPick").then((res) => {
                    console.log('pickedEvent', res)
                });
            });
        });
        // 创建Cesium视口
        const viewer = objm.createCesiumViewer(document.getElementById("app"));

        // 通过json创建一个影像图层
        const imageryLayer = objm.createSceneObjectFromJson({
            id: "9812a65f-0de0-4f7b-b234-809c0c2fb8ef",
            type: "ESImageryLayer",
            url: "https://server.arcgisonline.com/arcgis/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}",
        });

        /** ---------------------------------ESGeoJson------------------------------------**/
        let data = {
            "type": "FeatureCollection",
            "name": "shuisi84",
            "crs": {
                "type": "name",
                "properties": {
                    "name": "urn:ogc:def:crs:OGC:1.3:CRS84"
                }
            },
            "features": [
                {
                    "type": "Feature",
                    "properties": {
                        "OBJECTID": 1,
                        "name": "办公大楼",
                        "SHAPE_Length": 124.02104107024944,
                        "SHAPE_Area": 858.0744145512581
                    },
                    "geometry": {
                        "type": "MultiPolygon",
                        "coordinates": [
                            [
                                [
                                    [109.2041015625, 30.088107753367257],
                                    [115.02685546875, 30.088107753367257],
                                    [115.02685546875, 32.7872745269555],
                                    [109.2041015625, 32.7872745269555],
                                    [109.2041015625, 30.088107753367257]
                                ]
                            ],
                            [
                                [
                                    [112.9833984375, 26.82407078047018],
                                    [116.69677734375, 26.82407078047018],
                                    [116.69677734375, 29.036960648558267],
                                    [112.9833984375, 29.036960648558267],
                                    [112.9833984375, 26.82407078047018]
                                ]
                            ]
                        ]
                    }
                }
            ]
        }


        const sceneObject = objm.createSceneObject('ESGeoJson');
        sceneObject.allowPicking = true

        // url可以填写服务地址，也可以填写具体的data数据（如上所示）
        sceneObject.url = data
        // 额外存储属性
        sceneObject.extras = data
        // 线贴地
        sceneObject.fillGround = true
        // 面颜色
        sceneObject.fillColor = [1, 0, 0, 1]
        // 被拾取
        sceneObject.pickedEvent.don((e) => {
            console.log('pickedEvent', e)
            alert(JSON.stringify(e.geojsonPickInfo))
        })

        // 飞行定位
        const flyTo = () => {
            sceneObject.flyTo();
        };
    </script>
    <!-- 切换UE和Cesium引擎的组件（Vue） -->
    <div id="root">
        <switch-engine :objm="objm"></switch-engine>
    </div>
    <!-- Vue文件 -->
    <script src="./js/vue.global.js"></script>
    <!-- 切换UE和Cesium的组件 -->
    <script src="./js/switchEngineCom.js"></script>
</body>

</html>